#include "InfoManager.h"

InfoManager::InfoManager()
{
	resGroupMgr = ResourceGroupManager::getSingletonPtr();
	resGroupMgr->addResourceLocation(FONT_FOLDER, "FileSystem");
	
	fontMgr = FontManager::getSingletonPtr();
	
	font = fontMgr->create("MyFont", "General");
	font->setParameter("type","truetype");
	font->setParameter("source",FONT_FILE_NAME);
	font->setParameter("size","26");
	font->setParameter("resolution","96");
	font->load();
	
	overlayMgr = OverlayManager::getSingletonPtr();
	
	create_new_overlay("EnemyPanel", "EnemyArea", "EnemyOverlay", 600, 450, 15);
	create_new_overlay("EnemyKillPanel", "EnemyKillArea", "EnemyKillOverlay", 600, 470, 15);
	create_new_overlay("LivesPanel", "LivesArea", "LivesOverlay", 600, 490, 15);
	create_new_overlay("BoostPanel", "BoostArea", "BoostOverlay", 500, 510, 15);
	create_new_overlay("FPSPanel", "FPSArea", "FPSOverlay", 500, 530, 13);
	
}

void InfoManager::create_new_overlay(string panelname, string areaname,
	string overlayname, int xpos, int ypos, int charheight)
{
	// Create the panel
	panel = static_cast<OverlayContainer*>(
 	  overlayMgr->createOverlayElement("Panel", panelname));
	panel->setMetricsMode(Ogre::GMM_PIXELS);
	panel->setPosition(xpos, ypos);
	
	// Create the textarea
	textArea = static_cast<TextAreaOverlayElement*>(
   		overlayMgr->createOverlayElement("TextArea", areaname));
	textArea->setMetricsMode(Ogre::GMM_PIXELS);
	textArea->setPosition(0, 0);
	
	textArea->setCharHeight(charheight);
	textArea->setFontName("MyFont");
	textArea->setCaption("Lives: "); 

	// Create the overlay
	overlay = overlayMgr->create(overlayname);
	overlay->add2D(panel);
	panel->addChild(textArea);

	overlay->show();
}

void InfoManager::update_overlay(string which, string capt, int val)
{
	OverlayElement* thisTextArea = OverlayManager::getSingleton().getOverlayElement(which);
	capt = (val == NULL) ? capt : capt + to_string(val);
	thisTextArea->setCaption(string(capt));
}

string InfoManager::to_string(int val)
{
	stringstream out;
	out << val;
	return out.str();
}

string InfoManager::to_string(float val)
{
	stringstream out;
	out << val;
	return out.str();
}
